//
//  OilCarListCell.m
//  Base_App
//
//  Created by Yutian Duan on 2019/5/30.
//  Copyright © 2019年 Wanwin. All rights reserved.
//

#import "OilCardListCell.h"

static CGFloat textFont = 13.0f;

@interface OilCardListCell () {
  NSMutableArray <UIView *>*tempArray;
}

@end

@implementation OilCardListCell

- (void)awakeFromNib {
  [super awakeFromNib];

}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  [super setSelected:selected animated:animated];
  
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  
  self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  if (self) {
    self.contentView.backgroundColor = DEF_BgColor;
    tempArray = [[NSMutableArray alloc] init];
    [self setupDefault];
  }
  return self;
}

- (void)setupDefault {

  _applyNumberLabel = [[UILabel alloc] init];
  _applyNumberLabel.textColor = DEF_GRAY;
  _applyNumberLabel.textAlignment = NSTextAlignmentLeft;
  _applyNumberLabel.font = [UIFont systemFontOfSize:textFont];
  [self.contentView addSubview:_applyNumberLabel];
  
  _cnNameLabel = [[UILabel alloc] init];
  _cnNameLabel.textColor = DEF_BLACK;
  _cnNameLabel.textAlignment = NSTextAlignmentLeft;
  _cnNameLabel.font = _applyNumberLabel.font;
  [self.contentView addSubview:_cnNameLabel];
  
  _enNameLabel = [[UILabel alloc] init];
  _enNameLabel.textColor = DEF_BLACK;
  _enNameLabel.textAlignment = NSTextAlignmentLeft;
  _enNameLabel.font = _applyNumberLabel.font;
  [self.contentView addSubview:_enNameLabel];
  
  _phoneNumberLabel = [[UILabel alloc] init];
  _phoneNumberLabel.textColor = DEF_BLACK;
  _phoneNumberLabel.textAlignment = NSTextAlignmentLeft;
  _phoneNumberLabel.font = _applyNumberLabel.font;
  [self.contentView addSubview:_phoneNumberLabel];
  
  [_applyNumberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
    make.leading.mas_equalTo(self.contentView.mas_leading).offset(20);
    make.top.mas_equalTo(self.contentView.mas_top).offset(20);
    make.height.mas_equalTo(@20);
    make.trailing.mas_equalTo(self.contentView.mas_centerX);
  }];
  
  [_cnNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
    make.leading.height.trailing.mas_equalTo(self.applyNumberLabel);
    make.top.mas_equalTo(self.applyNumberLabel.mas_bottom).offset(5);
  }];
  
  [_enNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
    make.top.height.mas_equalTo(self.cnNameLabel);
    make.trailing.mas_equalTo(self.contentView.mas_trailing).offset(-20);
    make.leading.mas_equalTo(self.cnNameLabel.mas_trailing).offset(0);
  }];
  
  
  [_phoneNumberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
    make.leading.height.trailing.mas_equalTo(self.applyNumberLabel);
    make.top.mas_equalTo(self.cnNameLabel.mas_bottom).offset(5);
  }];
  
  
}

- (void)setModel:(OilCardListModel *)model {
  _model = model;
  [self setupData];
}

- (void)setupData {
  
  _applyNumberLabel.text = [NSString stringWithFormat:@"%@: %@",YTLocalizedString(@"申请编号"),@"201902221535"];
  _cnNameLabel.text = [NSString stringWithFormat:@"%@: %@",YTLocalizedString(@"中文姓名"),@"陈大文"];
  _enNameLabel.text = [NSString stringWithFormat:@"%@: %@",YTLocalizedString(@"英文姓名"),@"Kenny Chan"];
  _phoneNumberLabel.text = [NSString stringWithFormat:@"%@: %@",YTLocalizedString(@"手机号码"),@"9545 0440"];
  
  [tempArray makeObjectsPerformSelector:@selector(removeFromSuperview)];
  [tempArray removeAllObjects];
  
  // 90 ->
  
  for (NSInteger i = 0; i < _model.stepArray.count; i++) {
    
    [self setupContentView:i];
  }
  
}

///! 设置车牌进展View
- (void)setupContentView:(NSInteger )row {
  
  
  
  UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 35)];
  [self.contentView addSubview:contentView];
  
  [tempArray addObject:contentView];
  
  
  UILabel *textLabel = [[UILabel alloc] init];
  textLabel.font = [UIFont systemFontOfSize:textFont];
  textLabel.textAlignment = NSTextAlignmentLeft;
  [contentView addSubview:textLabel];
  
  UIImageView *stepImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
  [contentView addSubview:stepImageView];
  
  UILabel *statusLabel = [[UILabel alloc] init];
  statusLabel.font = [UIFont systemFontOfSize:textFont];
  statusLabel.textAlignment = NSTextAlignmentLeft;
  [contentView addSubview:statusLabel];
  ///!
  textLabel.text = [NSString stringWithFormat:@"%@:  %@",YTLocalizedString(@"车牌号码"),@"BW4567"];
  stepImageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"OilCardStep%zd",row]];
  statusLabel.text = YTLocalizedString(@"审核中");
  statusLabel.textColor = DEF_RED;
  
  
  [contentView mas_makeConstraints:^(MASConstraintMaker *make) {
    make.leading.trailing.mas_equalTo(self.contentView);
    make.height.mas_equalTo(@35);
    make.top.mas_equalTo(self.phoneNumberLabel.mas_bottom).offset(10+row * 35);
  }];
  
  [textLabel mas_makeConstraints:^(MASConstraintMaker *make) {
    make.leading.mas_equalTo(contentView.mas_leading).offset(20);
    make.top.bottom.mas_equalTo(contentView);
    make.trailing.mas_equalTo(contentView.mas_centerX).offset(-30);
  }];
  
  [stepImageView mas_makeConstraints:^(MASConstraintMaker *make) {
    make.centerY.mas_equalTo(contentView.mas_centerY);
    make.leading.mas_equalTo(textLabel.mas_trailing).offset(5);
    make.trailing.mas_equalTo(statusLabel.mas_leading).offset(-10);
    make.height.mas_equalTo(@1.5);
  }];
  
  [statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
    make.top.bottom.mas_equalTo(contentView);
    make.trailing.mas_equalTo(contentView.mas_trailing).offset(-20);
    make.width.mas_equalTo(60);
  }];
}

@end

